package com.smartlifev30.baiwei.adapter;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartlifev30.R;
import com.smartlifev30.baiwei.bean.HomeContentItem;
import com.smartlifev30.baiwei.view.recyclerViewComponent.BaseAdapter;
import com.smartlifev30.baiwei.view.recyclerViewComponent.BaseViewHolder;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 九宫格
 * @author tys
 * @date 2018/8/15
 */

public class HomeContentAdapter extends BaseAdapter<HomeContentItem, HomeContentAdapter.ViewHolder> {
    public HomeContentAdapter(Context context, ArrayList<HomeContentItem> data) {
        super(context, data);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.home_content_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        HomeContentItem data = getData(position);
        holder.textView.setText(data.getDes());
        holder.imageView.setImageResource(data.getDrawableResId());
    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.home_content_iv)
        ImageView imageView;
        @BindView(R.id.home_content_tv)
        TextView textView;

        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            setItemClickListen(itemView, HomeContentAdapter.this);
        }
    }
}
